﻿using System;

namespace EOS.Framework.Rules
{
    /// <summary>
    /// Rule to verify zipcodes.
    /// </summary>
    public class ZipcodeRule : RegexRule
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ZipcodeRule"/> class
        /// with a description.
        /// </summary>
        /// <param name="brokenDescription">A description of the rule that will be shown
        /// if the rule is broken. Cannot be null or empty or contains only whitespaces.</param>
        /// <exception cref="ArgumentNullException"><paramref name="brokenDescription"/> is
        /// null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="brokenDescription"/> is a string
        /// of length 0 or contains only blanks.</exception>
        public ZipcodeRule(string brokenDescription)
            : this(brokenDescription, false)
        { }

        /// <summary>
        /// Initializes a new instance of the <see cref="ZipcodeRule"/> class
        /// with a description and a flag, indicating, if the value can be empty.
        /// </summary>
        /// <param name="canBeEmpty">if set to <c>true</c> the value can be empty.</param>
        /// <param name="brokenDescription">A description of the rule that will be shown
        /// if the rule is broken. Cannot be null or empty or contains only whitespaces.</param>
        /// <exception cref="ArgumentNullException"><paramref name="brokenDescription"/> is
        /// null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="brokenDescription"/> is a string
        /// of length 0 or contains only blanks.</exception>
        public ZipcodeRule(string brokenDescription, bool canBeEmpty)
            : base(brokenDescription, 
            "^[0-9]{4,5}$", 
            canBeEmpty)
        { }
    }
}